<template>
	<view class="my-class-page">
		<view class="list-area" v-for="item in studentList" :key="item._id" @click="toClassDetail(item)">
			<view class="list-top">
				<view class="">课程名称：<view class="list-text">{{item.title}}</view>
				</view>
				<view class="">学员姓名：<view class="list-text">{{item.learnerNm}}</view>
				</view>
			</view>
			<view style="position: absolute;right: 5px;bottom: 5px;">
				<view class="list-btn" :class="item.payStatus == 0 ? 'no-pay':'is-pay'">
					{{item.payStatus == 0 ? '未支付':'已支付'}}
				</view>
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	const db = uniCloud.database()
	export default {
		data() {
			return {
				userInfo: {},
				studentList: []
			}
		},
		onLoad(e) {},
		onReady() {},
		onShow() {
			const _this = this
			uni.getStorage({
				key: 'userInfo',
				success: function(res) {
					if (res.data) {
						_this.userInfo = res.data
						_this.getCourseReg(res.data)
					}
				},
				fail: function(res) {
					uni.navigateTo({
						url: '../login/login'
					});
				}
			})
		},
		created() {},
		mounted() {},
		methods: {
			getCourseReg(userInfo) {
				const where = `"applicationPhone"=="${userInfo.phone}"`
				return db.collection('course-registration').where(where)
					.field('applicationPhone,courseId,classId,learnerNm,learnerId,classTime,allClassTime,payStatus,title').get().then((res) => {
						const data = res.result.data
						if (data) {
							this.studentList = data
						}
						console.log(res)
					}).catch((err) => {
						uni.showModal({
							content: err.message || '请求服务失败',
							showCancel: false
						})
					})
			},
			toClassDetail (item) {
				if (item.payStatus == 0 || !item.classId) {
					uni.showModal({
						content: '未分班！',
						showCancel: false
					})
					return
				}
				uni.navigateTo({
					url: `./myInfo?parm=${JSON.stringify(item)}`
				});
			}
		}
	}
</script>

<style>
	.my-class-page {
		padding: 10px;
	}

	.list-area {
		height: 120px;
		border: 1px solid #fc993b;
		padding: 5px;
		margin-bottom: 20px;
		box-shadow: 1px 1px 2px 1px #fc993b;
		cursor: pointer;
		position: relative;
	}

	.list-top {
		display: flex;
		margin-bottom: 20px;
	}

	.list-top view {
		flex: 1;
	}

	.list-btn {
		text-align: center;
		width: 80px;
		height: 30px;
		line-height: 30px;
		color: #fff;
		display: inline-block;
	}

	.list-text {
		margin-top: 10px;
		color: #888;
	}

	.no-pay {
		background-color: darkred;
	}

	.is-pay {
		background-color: green;
	}
</style>
<style lang="scss">
</style>